
//
//  findVC.m
//  CMAccountBook
//
//  Created by 王开政 on 2018/10/30.
//  Copyright © 2018年 王开政. All rights reserved.
//

#import "findVC.h"

@interface findVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic, strong) UITableView *Tab;

@property(nonatomic,strong)UIView *navigationView;

@property(nonatomic,strong)UILabel *titleLabel;

@property(nonatomic,strong)UILabel *nameLabel;

@property(nonatomic,strong)UILabel *dataLabel;
@property(nonatomic,strong)UIButton *dataBtn;

@property(nonatomic,strong)UILabel *incomeLabel;
@property(nonatomic,strong)UILabel *income;

@property(nonatomic,strong)UILabel *expendLabel;
@property(nonatomic,strong)UILabel *expend;

@property(nonatomic,strong)UILabel *surplusLabel;
@property(nonatomic,strong)UILabel *surplus;


@property(nonatomic, strong) UIView *headView;

@end

@implementation findVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    self.navigationController.navigationBarHidden=YES;
    [self.view addSubview:self.navigationView];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
    
    [self.view addSubview:self.Tab];
    // Do any additional setup after loading the view.
}
-(UIView *)navigationView{
    if (!_navigationView) {
        _navigationView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, SafeAreaTopHeight)];
        _navigationView.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
        [_navigationView addSubview:self.titleLabel];
//        [_navigationView addSubview:self.rightButton];
    }
    return _navigationView;
}
-(UILabel *)titleLabel{
    
    if (!_titleLabel) {
        
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,SafeAreaTopHeight - 44, ScreenWidth, 44)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = KblackColor;
        [_titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17*kfit]];
        _titleLabel.text = @"发现";
        
    }
    return _titleLabel;
}
-(UILabel *)nameLabel{
    
    if (!_nameLabel) {
        
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*kfit,15*kfit, 40*kfit, 20*kfit)];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.textColor = KblackColor;
        _nameLabel.font = [UIFont systemFontOfSize:14*kfit];
        _nameLabel.text = @"流水";
        
    }
    return _nameLabel;
}
-(UILabel *)dataLabel{
    if (!_dataLabel) {
        _dataLabel = [[UILabel alloc]initWithFrame:CGRectMake(20*kfit,62*kfit, 80*kfit, 20*kfit)];
//        _dataLabel.textAlignment = NSTextAlignmentCenter;
        _dataLabel.font = [UIFont systemFontOfSize:12*kfit];
        _dataLabel.text = @"2018年";
        _dataLabel.textColor = [UIColor colorWithHexString:@"#101010"];
    }
    return _dataLabel;
}
-(UILabel *)incomeLabel{
    if (!_incomeLabel) {
        _incomeLabel = [[UILabel alloc]initWithFrame:CGRectMake(113*kfit, 62*kfit, 80*kfit, 20*kfit)];
        //        _incomeLabel.textAlignment = NSTextAlignmentCenter;
        _incomeLabel.font = [UIFont systemFontOfSize:12*kfit];
        _incomeLabel.text = @"收入";
        _incomeLabel.textColor = [UIColor colorWithHexString:@"#a2a2a2"];
    }
    return _incomeLabel;
}
-(UILabel *)expendLabel{
    if (!_expendLabel) {
        _expendLabel = [[UILabel alloc]initWithFrame:CGRectMake(197*kfit, 62*kfit, 80*kfit, 20*kfit)];
        //        _incomeLabel.textAlignment = NSTextAlignmentCenter;
        _expendLabel.font = [UIFont systemFontOfSize:12*kfit];
        _expendLabel.text = @"支出";
        _expendLabel.textColor = [UIColor colorWithHexString:@"#a2a2a2"];
    }
    return _expendLabel;
}
-(UILabel *)surplusLabel{
    if (!_surplusLabel) {
        _surplusLabel = [[UILabel alloc]initWithFrame:CGRectMake(285*kfit, 62*kfit, 80*kfit, 20*kfit)];
        //        _incomeLabel.textAlignment = NSTextAlignmentCenter;
        _surplusLabel.font = [UIFont systemFontOfSize:12*kfit];
        _surplusLabel.text = @"结余";
        _surplusLabel.textColor = [UIColor colorWithHexString:@"#a2a2a2"];
    }
    return _surplusLabel;

}
-(UIButton *)dataBtn{
    if (!_dataBtn) {
        _dataBtn = [[UIButton alloc]initWithFrame:CGRectMake(0*kfit, 93*kfit, 80*kfit, 25*kfit)];
        [_dataBtn setTitle:@"10月" forState:0];
        [_dataBtn setTitleColor:[UIColor colorWithHexString:@"#ffffff"] forState:0];
        [_dataBtn setImage:[UIImage imageNamed:@"choose_down_black"] forState:UIControlStateNormal];
        // button标题的偏移量
        _dataBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -_dataBtn.imageView.bounds.size.width+2, 0, _dataBtn.imageView.bounds.size.width);
        // button图片的偏移量
        _dataBtn.imageEdgeInsets = UIEdgeInsetsMake(0, _dataBtn.titleLabel.bounds.size.width, 0, -_dataBtn.titleLabel.bounds.size.width);
        
        //        [_dataBtn addTarget:self action:@selector(aaa) forControlEvents:UIControlEventTouchUpInside];
    }
    return _dataBtn;
}
-(UILabel *)income{
    if (!_income) {
        _income = [[UILabel alloc]initWithFrame:CGRectMake(113*kfit, 93*kfit, 80*kfit, 20*kfit)];
        //        _incomeLabel.textAlignment = NSTextAlignmentCenter;
        _income.font = [UIFont systemFontOfSize:18*kfit];
        _income.text = @"0.00";
        _income.textColor = [UIColor colorWithHexString:@"#ffffff"];
    }
    return _income;
}
-(UILabel *)expend{
    if (!_expend) {
        _expend = [[UILabel alloc]initWithFrame:CGRectMake(197*kfit, 93*kfit, 80*kfit, 20*kfit)];
        //        _incomeLabel.textAlignment = NSTextAlignmentCenter;
        _expend.font = [UIFont systemFontOfSize:18*kfit];
        _expend.text = @"0.00";
        _expend.textColor = [UIColor colorWithHexString:@"#ffffff"];
    }
    return _expend;
}
-(UILabel *)surplus{
    if (!_surplus) {
        _surplus = [[UILabel alloc]initWithFrame:CGRectMake(285*kfit, 93*kfit, 80*kfit, 20*kfit)];
        //        _incomeLabel.textAlignment = NSTextAlignmentCenter;
        _surplus.font = [UIFont systemFontOfSize:18*kfit];
        _surplus.text = @"0.00";
        _surplus.textColor = [UIColor colorWithHexString:@"#ffffff"];
    }
    return _surplus;
}
-(UIView *)headView{
    if (!_headView) {
        _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 145*kfit)];
        _headView.backgroundColor = [UIColor whiteColor];
        [_headView addSubview:self.nameLabel];
        [_headView addSubview:self.dataBtn];
        [_headView addSubview:self.dataLabel];
        
        [_headView addSubview:self.income];
        [_headView addSubview:self.incomeLabel];
        [_headView addSubview:self.expend];
        
        [_headView addSubview:self.expendLabel];
        [_headView addSubview:self.surplus];
        [_headView addSubview:self.surplusLabel];
    }
    return _headView;
}
-(UITableView *)Tab{
    
    if (!_Tab) {
        _Tab = [[UITableView alloc]initWithFrame:CGRectMake(0,SafeAreaTopHeight, ScreenWidth, ScreenHeight-SafeAreaTopHeight-SafeAreaTabbarHeight)];
        _Tab.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
        _Tab.delegate = self;
        _Tab.dataSource = self;
        _Tab.scrollEnabled = NO;
        _Tab.showsVerticalScrollIndicator = NO;
    
//        _Tab.tableHeaderView = self.headView;
        _Tab.tableFooterView.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
        if(@available(iOS 11.0, *)){
            _Tab.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _Tab.estimatedRowHeight = 0;
            _Tab.estimatedSectionHeaderHeight = 0;
            _Tab.estimatedSectionFooterHeight = 0;
            
        }
        
    }
    
    return _Tab;
}
#pragma mark -设置cell横线左顶边
-(void)viewDidLayoutSubviews {
    if ([self.Tab respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.Tab setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.Tab respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.Tab setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
#pragma  make - UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
  
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        
    }
//    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {
        [cell addSubview:self.headView];
    }
    return cell;
}

#pragma  make - UITableViewDelegate
//返回高度，计算不同高度cell 一定要用，否则会出现偏移
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return 145;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 145)];
    view.backgroundColor = [UIColor colorWithHexString:@"#F6F6F8"];
    //    UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(21*kfit, 0, ScreenWidth/2, 35)];
    //    leftLabel.textColor = [UIColor colorWithHexString:@"#B7B7B7"];
    //    leftLabel.font = [UIFont systemFontOfSize:10*kfit];
    //    leftLabel.textAlignment = NSTextAlignmentLeft;
    //    leftLabel.text =self.sectionArray[section][@"data"];
    //
    //    UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2 -21*kfit, 0, ScreenWidth/2, 35)];
    //    rightLabel.textColor = [UIColor colorWithHexString:@"#B7B7B7"];
    //    rightLabel.font = [UIFont systemFontOfSize:10*kfit];
    //    rightLabel.textAlignment = NSTextAlignmentRight;
    //    rightLabel.text =self.sectionArray[section][@"money"];
    //
    //    [view addSubview:leftLabel];
    //    [view addSubview:rightLabel];
    
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
   
    
    
    
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}

-(void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    [super viewWillDisappear:animated];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
